package arithmetic;

/**
 * @program: javaLearn
 * @description: 移除元素
 * @author: renhai
 * @Date ：2022/3/10 22:27
 **/
public class removeElement {
    public int removeElement(int[] nums, int val) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        }
        int label1 = 0;
        while (label1 < n) {
            if (nums[label1] != val) {
                label1++;
            } else {
                break;
            }
        }
        int label2 = label1 + 1;
        while (label2 < n) {
            if (nums[label2] != val) {
                nums[label1] = nums[label2];
                label1++;
            }
            label2++;
        }
        return label1;
    }
}
